package com.swak.reactivex.transport;

import java.io.File;
import java.io.FileNotFoundException;
import java.net.InetSocketAddress;
import java.util.concurrent.CompletableFuture;

import org.springframework.util.Assert;

import com.swak.exception.RemotingException;
import com.swak.registry.URL;

/**
 * HeaderExchangePeer.
 * 
 * @author DELL
 */
public class HeaderExchangePeer implements ExchangePeer {
	private final Peer peer;
	private final ExchangeChannel channel;

	public HeaderExchangePeer(Peer peer) {
		Assert.notNull(peer, "peer can't be null");
		this.peer = peer;
		this.channel = new HeaderExchangeChannel(peer);
	}

	@Override
	public void close() {
		this.peer.close();
	}

	@Override
	public boolean isClosed() {
		return this.peer.isClosed();
	}

	@Override
	public URL url() {
		return this.channel.url();
	}

	@Override
	public boolean isConnected() {
		return this.channel.isConnected();
	}

	@Override
	public void send(Object message, boolean sent) throws RemotingException {
		this.channel.send(message, sent);
	}

	@Override
	public void sendFile(File file, boolean sent) throws RemotingException, FileNotFoundException {
		this.channel.sendFile(file, sent);
	}

	@Override
	public InetSocketAddress localAddress() {
		return this.channel.localAddress();
	}

	@Override
	public InetSocketAddress remoteAddress() {
		return this.channel.remoteAddress();
	}

	@Override
	public boolean hasAttribute(String key) {
		return this.channel.hasAttribute(key);
	}

	@Override
	public Object getAttribute(String key) {
		return this.channel.getAttribute(key);
	}

	@Override
	public void setAttribute(String key, Object value) {
		this.channel.setAttribute(key, value);
	}

	@Override
	public void removeAttribute(String key) {
		this.channel.removeAttribute(key);
	}

	@Override
	public CompletableFuture<Object> request(Object request) throws RemotingException {
		return this.channel.request(request);
	}

	@Override
	public CompletableFuture<Object> request(Object request, int timeout) throws RemotingException {
		return this.channel.request(request, timeout);
	}

	@Override
	public boolean isUnicast() {
		return this.peer.isUnicast();
	}
}
